package GUIs;

//author dimi

import javax.persistence.EntityManager;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

 
public class CProfile_NewPasswordGUI extends javax.swing.JFrame {
    private EntityManager em;
   
    // Ορίζω ως γονέα τη φόρμα CustomerGUI
    private CustomerGUI parent;
   
    public CProfile_NewPasswordGUI(CustomerGUI parent, EntityManager em) {
        this.em = em;
        this.parent = parent;
        initComponents();
        setLocationRelativeTo(null); // Κεντράρει το παράθυρο στην οθόνη
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Panel_NewPassword_Welcome = new javax.swing.JPanel();
        Label_NewPassword_Welcome = new javax.swing.JLabel();
        Button_NewPassword_Exit = new javax.swing.JButton();
        Label_NewPassword_InsertOld = new javax.swing.JLabel();
        PasswordField_OldPassword = new javax.swing.JPasswordField();
        PasswordField_NewPassword = new javax.swing.JPasswordField();
        PasswordField_NewPasswordReentry = new javax.swing.JPasswordField();
        Label_NewPassword_InsertNew = new javax.swing.JLabel();
        Label_NewPassword_ReenterNew = new javax.swing.JLabel();
        Button_AcceptChange = new java.awt.Button();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setBackground(new java.awt.Color(153, 153, 255));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        Panel_NewPassword_Welcome.setBackground(new java.awt.Color(0, 153, 153));

        Label_NewPassword_Welcome.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        Label_NewPassword_Welcome.setForeground(new java.awt.Color(153, 255, 255));
        Label_NewPassword_Welcome.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Label_NewPassword_Welcome.setText("ΦΟΡΜΑ ΑΛΛΑΓΗΣ ΚΩΔΙΚΟΥ ΕΙΣΟΔΟΥ");

        javax.swing.GroupLayout Panel_NewPassword_WelcomeLayout = new javax.swing.GroupLayout(Panel_NewPassword_Welcome);
        Panel_NewPassword_Welcome.setLayout(Panel_NewPassword_WelcomeLayout);
        Panel_NewPassword_WelcomeLayout.setHorizontalGroup(
            Panel_NewPassword_WelcomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel_NewPassword_WelcomeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Label_NewPassword_Welcome, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        Panel_NewPassword_WelcomeLayout.setVerticalGroup(
            Panel_NewPassword_WelcomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Panel_NewPassword_WelcomeLayout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addComponent(Label_NewPassword_Welcome)
                .addGap(21, 21, 21))
        );

        Button_NewPassword_Exit.setText("ΕΞΟΔΟΣ");
        Button_NewPassword_Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button_NewPassword_ExitActionPerformed(evt);
            }
        });

        Label_NewPassword_InsertOld.setBackground(new java.awt.Color(0, 153, 153));
        Label_NewPassword_InsertOld.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Label_NewPassword_InsertOld.setForeground(new java.awt.Color(0, 153, 153));
        Label_NewPassword_InsertOld.setText("Εισάγετε το παλιό password");
        Label_NewPassword_InsertOld.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        PasswordField_OldPassword.setText("ggg");
        PasswordField_OldPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PasswordField_OldPasswordActionPerformed(evt);
            }
        });

        PasswordField_NewPassword.setText("jPasswordField1");
        PasswordField_NewPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PasswordField_NewPasswordActionPerformed(evt);
            }
        });

        PasswordField_NewPasswordReentry.setText("jPasswordField1");
        PasswordField_NewPasswordReentry.setToolTipText("Πρέπει να εισάγετε εκ νέου το νέο κωδικό προς επαλήθευσή του!");
        PasswordField_NewPasswordReentry.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PasswordField_NewPasswordReentryActionPerformed(evt);
            }
        });

        Label_NewPassword_InsertNew.setBackground(new java.awt.Color(0, 153, 153));
        Label_NewPassword_InsertNew.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Label_NewPassword_InsertNew.setForeground(new java.awt.Color(0, 153, 153));
        Label_NewPassword_InsertNew.setText("Εισάγετε το νέο password");
        Label_NewPassword_InsertNew.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        Label_NewPassword_ReenterNew.setBackground(new java.awt.Color(0, 153, 153));
        Label_NewPassword_ReenterNew.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Label_NewPassword_ReenterNew.setForeground(new java.awt.Color(0, 153, 153));
        Label_NewPassword_ReenterNew.setText("Εισάγετε το νέο password για επαλήθευση");
        Label_NewPassword_ReenterNew.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        Button_AcceptChange.setBackground(new java.awt.Color(0, 102, 102));
        Button_AcceptChange.setForeground(new java.awt.Color(153, 255, 255));
        Button_AcceptChange.setLabel("ΑΠΟΔΟΧΗ");
        Button_AcceptChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button_AcceptChangeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Panel_NewPassword_Welcome, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(Button_NewPassword_Exit))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Label_NewPassword_InsertOld, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(PasswordField_OldPassword))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Label_NewPassword_InsertNew, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(PasswordField_NewPassword))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Label_NewPassword_ReenterNew, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(PasswordField_NewPasswordReentry)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(Button_AcceptChange, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(159, 159, 159))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(Panel_NewPassword_Welcome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(Label_NewPassword_InsertOld, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(PasswordField_OldPassword))
                .addGap(41, 41, 41)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Label_NewPassword_InsertNew, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(PasswordField_NewPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(Label_NewPassword_ReenterNew, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(PasswordField_NewPasswordReentry))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                .addComponent(Button_AcceptChange, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(Button_NewPassword_Exit))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Button_NewPassword_ExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button_NewPassword_ExitActionPerformed
        System.out.println("Επιλογή Εξόδου από τη φόρμα Αλλαγής Password");
        parent.setEnabled(true); // Ενεργοποιώ πάλι το παράθυρο της προηγούμενης φόρμας
        dispose();
    }//GEN-LAST:event_Button_NewPassword_ExitActionPerformed

   
    private void Button_AcceptChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button_AcceptChangeActionPerformed
        
        String old_password = new String(PasswordField_OldPassword.getPassword());
        if(old_password.equals("")){
            JOptionPane.showMessageDialog(this, "Πρέπει να εισάγετε τον παλιό σας κωδικό","Εισαγωγή Δεδομένων",JOptionPane.WARNING_MESSAGE);
            return;
        }
        
        String new_password1 = new String(PasswordField_NewPassword.getPassword());
        if(new_password1.equals("")){
            JOptionPane.showMessageDialog(this, "Πρέπει να εισάγετε το νέο κωδικό","Εισαγωγή Δεδομένων",JOptionPane.WARNING_MESSAGE);
            return;
        }
        
        // Σε αυτό το σημείο πρέπει να ελεγχθεί αν ο κωδικός που πληκτρολογήθηκε
        // συμπίπτει με τον κωδικό, που αντιστοιχεί στον εκάστοτε χρήστη
        // ToDO
        
        String new_password2 = new String(PasswordField_NewPasswordReentry.getPassword());
        if(new_password2.equals("")){
            JOptionPane.showMessageDialog(this, "Πρέπει να εισάγετε ξανά το νέο κωδικό","Εισαγωγή Δεδομένων",JOptionPane.WARNING_MESSAGE);
            return;
        }
    }//GEN-LAST:event_Button_AcceptChangeActionPerformed

    private void PasswordField_NewPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PasswordField_NewPasswordActionPerformed
        
    }//GEN-LAST:event_PasswordField_NewPasswordActionPerformed

    private void PasswordField_NewPasswordReentryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PasswordField_NewPasswordReentryActionPerformed
        
    }//GEN-LAST:event_PasswordField_NewPasswordReentryActionPerformed

    private void PasswordField_OldPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PasswordField_OldPasswordActionPerformed
        
    }//GEN-LAST:event_PasswordField_OldPasswordActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        System.out.println("Επιλογή Εξόδου από τη φόρμα Αλλαγής Password");
        parent.setEnabled(true); // Ενεργοποιώ πάλι το παράθυρο της προηγούμενης φόρμας
        dispose();
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button Button_AcceptChange;
    private javax.swing.JButton Button_NewPassword_Exit;
    private javax.swing.JLabel Label_NewPassword_InsertNew;
    private javax.swing.JLabel Label_NewPassword_InsertOld;
    private javax.swing.JLabel Label_NewPassword_ReenterNew;
    private javax.swing.JLabel Label_NewPassword_Welcome;
    private javax.swing.JPanel Panel_NewPassword_Welcome;
    private javax.swing.JPasswordField PasswordField_NewPassword;
    private javax.swing.JPasswordField PasswordField_NewPasswordReentry;
    private javax.swing.JPasswordField PasswordField_OldPassword;
    // End of variables declaration//GEN-END:variables
}
